const { ListNode, LinkedList } = require('./1. 建立线性链表')

function change(linkedList, index, val) {
    let count = 0
    let cur = linkedList.head
    while (cur && count < index) {
        count += 1
        cur = cur.next
    }
    if (!cur) {
        return 'Error'
    }
    cur.val = val
}

let linkedList = new LinkedList([2, 3, 5, 6, 8, 1])
change(linkedList, 2, 1)
console.log(linkedList);